<?php
namespace Orm\PlayActive;

use Base\Exception\RmException;
class PlayActiveClass extends \Base\BaseOrmObject{
    protected   $id,
				$uid = 0, // 竞猜用户ID
                $play_type = 1, //竞猜类型
				$play_show_id = 0, // 比赛赛程ID
				$play_target_id = 0, // 竞猜选项ID
				$multiple = 0, // 倍数
				$put_date = '', // 投注日期
				$status = 0, // 1，猜中，2，猜错
				$is_del = 0,
				$insert_time = '',
				$update_time = '';

    function __init($data)
    {
        parent::__init($data);
        $this->dformat($data);
    }

    private function dformat()
    {
    }

    public function loadById($id = 0)
    {
        $model = new \Orm\PlayActive\PlayActiveModel();
        $data = $model->loadById($id);
        self::__init($data);
    }

    public function insert()
    {
        $this->checkNecessaryParam();
        $data = array(
            'uid' => $this->uid,
            'play_type' => $this->play_type,
			'play_show_id' => $this->play_show_id,
			'play_target_id' => $this->play_target_id,
			'multiple' => $this->multiple,
			'put_date' => $this->put_date,
			'status' => $this->status,
        );

        $model = new \Orm\PlayActive\PlayActiveModel();
        $model->insert($data);
        $this->id = $model->getLastId();
    }

    public function update()
    {
        $this->checkNecessaryParam();
        $data = array(
            'uid' => $this->uid,
            'play_type' => $this->play_type,
			'play_show_id' => $this->play_show_id,
			'play_target_id' => $this->play_target_id,
			'multiple' => $this->multiple,
			'put_date' => $this->put_date,
			'status' => $this->status,
        );

        $model = new \Orm\PlayActive\PlayActiveModel();
        $is_update = $model->update($data, "`id` = {$this->id}");
        return $is_update;
    }

    public function delete($id)
    {
        $data = array('is_del'=>1);
        $model = new \Orm\PlayActive\PlayActiveModel();
        $model->update($data, "`id` = {$id}");
    }

    private function checkNecessaryParam()
    {
    }
}